package FirstQuestion;

import java.util.Arrays;
import java.util.Scanner;

public class GuessMachine {

    public int initial(){
        int result=(int)(Math.random()*3)+1;
        return result;
    }

    public String guess(int num,int result) {
            if (num == result) {
                return "恭喜你猜对了";
            } else {
                if (num > result) {
                    return "再小一点";
                }
                if (num < result) {
                    return "再大一点";
                }
            }

            return "很遗憾，你没有机会再猜了";
        }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
       Commodity commodity[]={new Commodity(1,"小米电视",3399.0),
                              new Commodity(2,"LG电视",5999.0),
                              new Commodity(3,"海尔电视",12999.0)
       };
       GuessMachine guessMachine=new GuessMachine();
       int result=guessMachine.initial();
        System.out.println("电视商品列表");
        System.out.println("编号\t商品名\t价格");
        for (Commodity C:commodity) {
            C.show();
        }
        System.out.println(commodity[result-1]);

        int count=1;
        while (count<=3){
            System.out.println("请输入:");
            int num=scanner.nextInt();
            String message=guessMachine.guess(num,result );
            System.out.println(message);
            if (num==result){
                break;
            }
            count++;
        }


    }
}